#pragma once

#include "Vector.h"
#include "BodyInfo.h"

class Circle;
class Line;
class Game;

struct ManifoldPoint;

class Primitive
{
	public:
		Primitive();
		Primitive(Vector vel, Vector angVel, float mass, float inertia, bool active);
		~Primitive() {}

		// Pure virtual functions
		// Returns the vector from this primitive to the point
		virtual Vector vectorTo(Vector p)=0;

		virtual void CollisionResponseWith(ManifoldPoint& point, float dt)=0;
		virtual void CollisionResponseWithCircle(ManifoldPoint& point, float dt)=0;
		virtual void CollisionResponseWithLine(ManifoldPoint& point, float dt)=0;

		void  CollisionResponse(ManifoldPoint& point, float dt);

		float toDegrees(float rad) const;

		void setData(BodyInfo* data) { m_data = data; }
		BodyInfo* getData() const { return m_data; }

		void	SetAngularVel(Vector v) { m_angularVel = v; }
		Vector	GetAngularVel() const;

		void	SetVel(float x, float y);
		Vector	GetVel()	const;
		float	GetMass()	const;
		void	SetMass(float mass);

		void	SetPos(float x, float y);
		Vector	GetPos()	const;
		Vector	GetAccel()	const;
	
		void setActive(bool v);
		bool getActive();

		float	GetInertia();

		bool	active() { return m_data->m_bActive; }
		float	mass()	 { return m_data->m_mass; }
		
		float   invMass() const { return m_invMass; }
		float	invInertia() const { return m_invInertia; }
		void	setInvMass(float v) { m_invMass = v; }
		void	setInvInertia(float v) { m_invInertia = v; }

		static float getElasticity() { return Elasticity; }
		static float getFriction() { return Friction; }

		static void setGame(Game* g) { m_game = g; }

		static void setElasticity(float v)
		{
			Elasticity = v;
		}
		static void setFriction(float v)
		{
			Friction = v;
		}

	protected:

		BodyInfo*		m_data;


		Vector	m_velocity;
		Vector m_accel;
		
		Vector	m_angularVel;
		Vector m_angularAccel;

		float	m_inertia;
		float	m_invInertia;
		float   m_invMass;

		Vector m_color;

		static Game* m_game;
		static float Elasticity;
		static float Friction;
};